<?php

/**
 * This is the model class for table "tbmuadichvu".
 *
 * The followings are the available columns in table 'tbmuadichvu':
 * @property string $id
 * @property integer $iduser
 * @property integer $iddichvu
 * @property string $ngaymua
 * @property string $ngaycapnhat
 * @property string $noidung
 * @property string $ketqua
 * @property double $gia
 * @property integer $trangthai
 * @property string $sodienthoai
 * @property string $ghichu
 *
 * The followings are the available model relations:
 * @property Tbdichvu $iddichvu0
 * @property Tbuser $iduser0
 */
class Muadichvu extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Muadichvu the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbmuadichvu';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('iduser, iddichvu, noidung, gia, trangthai', 'required'),
			array('iduser, iddichvu, trangthai', 'numerical', 'integerOnly'=>true),
			array('gia', 'numerical'),
			array('noidung', 'length', 'max'=>50),
			array('ketqua', 'length', 'max'=>500),
			array('sodienthoai', 'length', 'max'=>20),
			array('ghichu', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, iduser, iddichvu, ngaymua, ngaycapnhat, noidung, ketqua, gia, trangthai, sodienthoai, ghichu', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tbdichvu' => array(self::BELONGS_TO, 'Dichvu', 'iddichvu'),
			'tbuser' => array(self::BELONGS_TO, 'User', 'iduser'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'iduser' => 'Iduser',
			'iddichvu' => 'Iddichvu',
			'ngaymua' => 'Ngaymua',
			'ngaycapnhat' => 'Ngaycapnhat',
			'noidung' => 'Noidung',
			'ketqua' => 'Ketqua',
			'gia' => 'Gia',
			'trangthai' => 'Trangthai',
			'sodienthoai' => 'Sodienthoai',
			'ghichu' => 'Ghichu',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('iduser',$this->iduser);
		$criteria->compare('iddichvu',$this->iddichvu);
		$criteria->compare('ngaymua',$this->ngaymua,true);
		$criteria->compare('ngaycapnhat',$this->ngaycapnhat,true);
		$criteria->compare('noidung',$this->noidung,true);
		$criteria->compare('ketqua',$this->ketqua,true);
		$criteria->compare('gia',$this->gia);
		$criteria->compare('trangthai',$this->trangthai);
		$criteria->compare('sodienthoai',$this->sodienthoai,true);
		$criteria->compare('ghichu',$this->ghichu,true);
		$criteria->order = 'ngaymua DESC';
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}